<template>
	<view class="page">
		<rich-text :nodes="data"></rich-text>
		<template v-if="!data">
			<image :src="nodataImg" class="" mode="aspectFit"></image>
		</template>
		<tabbar :current="3"></tabbar>
	</view>
</template>

<script>
	import tabbar from './components/tabbar';
	import parseHtml from '@/static/js/parseHtml.js';
	import {
		$https
	} from '@/static/js/request.js';
	export default {
		data() {
			return {
				data: '',
				nodataImg: getApp().globalData.nodataImg
			};
		},
		onLoad(options) {
			this.getData(options.id);
			uni.setStorageSync('sourceId', options.id);
		},
		methods: {
			getDatas(id) {
				$https(
					'GETN',
					'companyQualification', {},
					res => {
						if (res.data.errcode == 0) {
							let result = res.data.data.content;
							let infos = this.formatRichText(result);
							this.data = parseHtml(infos);
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
						}
					},
				);
			},
			formatRichText(html) {
				let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
					match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
					match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
					match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
					return match;
				});
				newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
					match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
						'max-width:100%;');
					return match;
				});
				newContent = newContent.replace(/<br[^>]*\/>/gi, '');
				newContent = newContent.replace(/\<img/gi,
					'<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"');
				return newContent;
			}
		},
		components: {
			tabbar,
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #eff9f8;
	}

	.page {
		padding: 10rpx;
	}
</style>
